package com.zj.juc.study.cas;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author 自己的名字
 * @version 1.0.0
 * @ClassName CasAbaProblemDemo
 * @Description cas的aba问题演示
 * @createTime 2025年01月02日 22:56
 */
public class CasAbaProblemDemo {

    static AtomicInteger atomicInteger = new AtomicInteger(100);

    public static void main(String[] args) {
        new Thread(()->{
            atomicInteger.compareAndSet(100,101);

            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            atomicInteger.compareAndSet(101,100);
        }).start();

        try {
            TimeUnit.SECONDS.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        new Thread(()->{
            System.out.println("改动是否成功"+atomicInteger.compareAndSet(100, 2000));

        },"t2").start();

    }
}
